
'use strict';

/**
	Part of Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	@file
	@license AGPL-3.0+
*/


/*
	Zombie script example (= unprivileged)
	Do NOT require () this script from the addon code.
	
	demo_ID: 'simple'
*/


const {zombie, console} = require('zombie/zombie');
const {openWindow, closeAll} = require('zombie/webbrowser');
const {run, delay} = require('zombie/async');


zombie.print('zombie-navigator:', ' Hello, world!\n');

try {
run(function* () {
	console.log(zombie);
	
	console.log('Opening...');
	let w = yield openWindow('about:');
	console.log('Loaded:', w.uri);
	console.log('isPrivate:', w.isPrivate);
	
	console.log('Sleeping for 2s...');
	yield delay(2);
	
	console.log('Opening...');
	let w2 = yield openWindow('about:addons');
	console.log('Loaded:', w2.uri);
	
	console.log('Reloading...');
	yield w2.reload();
	console.log('Reloaded');
	
	console.log('Running a script');
	try {
		yield w2.runScript(function () {
			document.invalidFunc();
		});
		
		console.log('Script succeeded');
	} catch (e) {
		console.warn('Script exception:', e + '');
	}
	
	console.log('Closing...');
	yield closeAll();
	console.log('Closed');
})
.catch(function (e) {
	console.warn('Async error:', e);
	closeAll();
});
} catch (e) {
	console.warn('BUG?: Uncaught error:', e);
	closeAll();
}


// vim: ts=4 noet ai

